import { Pipe, PipeTransform } from '@angular/core';

/**
 * 售后方式转换文字
 */
@Pipe({ name: 'saleTypeStatus' })
export class saleTypeStatusPipe implements PipeTransform {
    transform(value: Number, exponent?: number): String {
        let str: String = "";
        switch (value) {
            case 1:
                str = "退货退款";
                break;
            case 2:
                str = "换货";
                break;
            case 3:
                str = "取消订单";
                break;
            case 4:
                str = "退款";
                break;
            case 5:
                str = "补货";
                break;
            default:
                str = "-";
                break;
        }
        return str;
    }
}
/**
 * 售后状态转换文字
 */
@Pipe({
  name: 'saleStatus',
  pure: false
})
export class saleStatusPipe implements PipeTransform {
    transform(value: Number, exponent?: number): String {
        let str: String = "";
        switch (value) {
          case 0:
            str = "用户提交申请（待审核）";
            break;
          case 1:
            str = "审核通过（待买家退货）";
            break;
          case 2:
            str = "退货超时";
            break;
          case 3:
            str = "商品已寄出";
            break;
          case 4:
            str = "待平台审核";
            break;
          case 5:
            str = "发起退款操作或直接退款";
            break;
          case 6:
            str = "售后成功";
            break;
          case 7:
            str = "售后失败";
            break;
          case 8:
            str = "已取消";
            break;
          default:
            str = "-";
            break;
        }
        return str;
    }
}
/**
 * 售后退款状态转换文字
 */
@Pipe({
  name: 'saleRefundStatus',
  pure: false
})
export class saleRefundStatusPipe implements PipeTransform {
    transform(value: Number, exponent?: number): String {
        let str: String = "";
        switch (value) {
          case 0:
            str = "未退款";
            break;
          case 1:
            str = "等待中";
            break;
          case 2:
            str = "退款成功";
            break;
          case 3:
            str = "退款失败";
            break;
          default:
            str = "-";
            break;
        }
        return str;
    }
}
/**
 * 订单类型转换文字
 */
@Pipe({
  name: 'orderTypeStatus',
  pure: false
})
export class orderTypeStatusPipe implements PipeTransform {
    transform(value: Number, exponent?: number): String {
        let str: String = "";
        switch (value) {
          case 1:
            str = "配件订单";
            break;
          case 2:
            str = "回收订单";
            break;
          case 3:
            str = "二手订单";
            break;
          case 4:
            str = "新机订单";
            break;
          default:
            str = "-";
            break;
        }
        return str;
    }
}
/**
 * 订单状态转换文字
 */
 @Pipe({
  name: 'orderStatus',
  pure: false
})
export class orderStatusPipe implements PipeTransform {
    transform(value: Number, exponent?: number): String {
        let str: String = "";
        switch (value) {
          case 0:
            str = "有效";
            break;
          case 1:
            str = "无效";
            break;
          case 2:
            str = "待付款";
            break;
          case 3:
            str = "待审核";
            break;
          case 4:
            str = "审核不通过";
            break;
          case 5:
            str = "审核通过";
            break;
          case 6:
            str = "排队发货";
            break;
          case 7:
            str = "待发货";
            break;
          case 8:
            str = "待收货（已发货）";
            break;
          case 9:
            str = "交易完成";
            break;
          case 10:
            str = "支付超时";
            break;
          case 11:
            str = "客服取消";
            break;
          case 12:
            str = "客户取消";
            break;
          case 13:
            str = "售后中";
            break;
          case 14:
            str = "全部退货";
            break;
          default:
            str = "-";
            break;
        }
        return str;
    }
}
/**
 * 物流状态转换文字
 */
@Pipe({
  name: 'expressStatus',
  pure: false
})
export class expressStatusPipe implements PipeTransform {
    transform(value: Number, exponent?: number): String {
        let str: String = "";
        switch (value) {
          case 0:
            str = "无轨迹";
            break;
          case 1:
            str = "已揽收";
            break;
          case 2:
            str = "在途中";
            break;
          case 201:
            str = "到达派件城市";
            break;
          case 202:
            str = "派件中";
            break;
          case 211:
            str = "已放入快递柜或驿站";
            break;
          case 3:
            str = "已签收";
            break;
          case 311:
            str = "已取出快递柜或驿站";
            break;
          case 4:
            str = "问题件";
            break;
          case 401:
            str = "发货无信息";
            break;
          case 402:
            str = "超时未签收";
            break;
          case 403:
            str = "超时未更新";
            break;
          case 404:
            str = "拒收（退件）";
            break;
          case 412:
            str = "快递柜或驿站超时未取";
            break;
          default:
            str = "-";
            break;
        }
        return str;
    }
}

/**
 * 收款状态
 */
 @Pipe({
  name: 'collectionStatus',
  pure: false
})
export class collectionStatusPipe implements PipeTransform {
  // 0：未付款 1：已付款 2：部分退款 3：全部退款
  transform(value: Number, exponent?: number): any {
      switch(value) {
        case 0:
          return '未付款';
        case 1:
          return '已付款';
        case 2:
          return '部分退款';
        case 3:
          return '全部退款';
        default:
          return '-'
      }
  }
}

/**
 * 收款状态
 * 订单状态数组：0-有效、1-无效、2-待付款、3-待审核、4-审核不通过、5-审核通过、6-排队发货、7-待发货、8-待收货（已发货）、9-交易完成、10-支付超时、11-客服取消、12-客户取消、13-售后中、14-全部退货
 */
 @Pipe({
  name: 'orderColorStatus',
  pure: false
})
export class orderColorStatus implements PipeTransform {
  // 待付款=2、支付超时=10、客户取消=12、客服取消=11、全部退货=14: '#ff0000', 
  // 待审核=3、排队发货=6、售后中=13：'#ff9900'，
  // 审核不通过=4、待评价：'#999999'，
  // 审核通过=5、交易完成=9：'#008000'，
  // 代发货=7、待收货=8：'#333333'
  transform(value: number, exponent?: number): any {
      if ([2, 10, 12, 11, 14].includes(value)) {
        return '#ff0000'
      } else if ([3, 6, 13].includes(value)) {
        return '#ff9900'
      } else if (value == 4) {
        return '#999999'
      } else if ([5, 9].includes(value)) {
        return '#008000'
      } else if ([7, 8].includes(value)) {
        return '#333333'
      } else {
        return '#333333'
      }
  }
}

/**
 * 支付方式(1:支付宝，2：微信，3：银联)
 * new (1：支付宝，2：财付通，3：敏付)
 */
@Pipe({
  name: 'platformStatus',
  pure: false
})
export class PlatformStatusPipe implements PipeTransform {
  transform(value: any, exponent?: any): any {
    switch (value) {
      case 1:
        return '支付宝';
      case 2:
        return '微信';
      case 3:
        return '银联';
      default:
        return '-';
    }
  }
}

/**
 * 退税管理 - 状态
 * 0 待审核 1.已打款 2.审核不通过 3.待打款
 */
@Pipe({ name: 'drawbackState' })
export class DrawbackStatePipe implements PipeTransform {
  transform(value: any, type?: string) {
    if (type == 'text') {
      switch (value) {
        case 0:
          return '待审核';
        case 1:
          return '已打款';
        case 2:
          return '审核不通过';
        case 3:
          return '待打款';
        default: 
          return '-';
      }
    } else {
      switch (value) {
        case 0:
          return '#417DE5';
        case 1:
          return '#008000';
        case 2:
          return '#FF0000';
        case 3:
          return '#FF9D2A';
        default: 
          return '#888888';
      }
    }
  }
}

// 财务二手回收账户类型
const accountTypeArrs = [
  { value: '111', label: '微信', color: '#87d068' },
  { value: '121', label: '支付宝', color: '#2db7f5' }
];

@Pipe({
  name: 'accountTypeStatus'
})
export class AccountTypeStatusPipe implements PipeTransform {
  transform(value: any, key: string = 'label') {
    let tempObj: any = {};
    tempObj = accountTypeArrs.find((item: any) => item.value === value);

    switch (key) {
      case 'label':
        return tempObj?.label || '-';
      case 'color':
        return tempObj?.color || '#606266';
    }
  }
}

// 验机分流水-收支类型：活动奖励、已失效、专业验机消费、购买验机分
export const financeMachineScoreTypeArrs = [
  {value: 1, label: '购买验机分'},
  {value: 2, label: '专业验机消费'},
  {value: 3, label: '活动奖励'},
  {value: 4, label: '已失效'}
]
@Pipe({
  name: 'financeMachineScoreTypes'
})
export class FinanceMachineScoreTypesPipe implements PipeTransform {
  transform(value: any) {
    let tempObj: any = financeMachineScoreTypeArrs.find((item: any) => item.value === value);
    return tempObj?.label || '-';
  }
}

// 财务-定制退款平台
export const refundPlatformArrs = [
  {value: 1, label: '支付宝'},
  {value: 2, label: '财付通'}
]
@Pipe({
  name: 'refundPlatformType'
})
export class RefundPlatformTypePipe implements PipeTransform {
  transform(value: any) {
    let tempObj: any = refundPlatformArrs.find((item: any) => item.value === value);
    return tempObj?.label || '-';
  }
}

// 财务-以旧换机订单 0：待生成 1：待打款(待发放) 2：打款完成(已发放) 3：打款失败
export const financeOrderChangeArrs = [
  {value: 0, label: '待生成'},
  {value: 1, label: '待发放'},
  {value: 2, label: '已发放'}
  // {value: 3, label: '打款失败'}
]
@Pipe({
  name: 'financeOrderChangeStatus'
})
export class FinanceOrderChangeStatusPipe implements PipeTransform {
  transform(value: any) {
    let tempObj: any = financeOrderChangeArrs.find((item: any) => item.value === value);
    return tempObj?.label || '-';
  }
}


/**
 * 订单状态 0-有效、1-无效、2-待付款、3-待审核、4-审核不通过、5-审核通过、6-排队发货、7-待发货、8-待收货（已发货）、9-交易完成、10-支付超时、11-客服取消、12-客户取消、13-售后中、14-全部退货 15-部分被抢
 */
export const secondOrderStateArrs = [
  {value: 0, label: '有效', color: '#666666'},
  {value: 1, label: '无效', color: '#666666'},
  {value: 2, label: '待付款', color: '#FF0000'},
  {value: 3, label: '待审核', color: '#FF9900'},
  {value: 4, label: '审核不通过', color: '#FF0000'},
  {value: 5, label: '审核通过', color: '#008000'},
  {value: 6, label: '排队发货', color: '#666666'},
  {value: 7, label: '待发货', color: '#FF9900'},
  {value: 8, label: '待收货（已发货）', color: '#666666'},
  {value: 9, label: '交易完成', color: '#008000'},
  {value: 10, label: '支付超时', color: '#FF0000'},
  {value: 11, label: '客服取消', color: '#FF0000'},
  {value: 12, label: '客户取消', color: '#FF0000'},
  {value: 13, label: '售后中', color: '#FF9900'},
  {value: 14, label: '全部退货', color: '#999999'},
  {value: 15, label: '部分被抢', color: '#FF0000'},
];

@Pipe({
  name: 'secondOrderStatus'
})
export class SecondOrderStatusPipe implements PipeTransform {
  transform(status: any, type: string) {
    let tempObj = secondOrderStateArrs.find((item: any) => {
      return item.value == status;
    })

    if (type == 'label') {
      return tempObj?.label || '-';
    } else if (type == 'color') {
      return tempObj?.color || '';
    } else {
      return '';
    }
  }
}

/**
 * ------------------------------ 报表 ------------------------------
 * 收款状态 0未付款 1已付款 2部分退款 3全部退款
 */
export const secondReportCollectionStateArrs = [
  {value: 0, label: '未付款', color: '#909399'},
  {value: 1, label: '已付款', color: '#67C23A'},
  {value: 2, label: '部分退款', color: '#E6A23C'},
  {value: 3, label: '全部退款', color: '#F56C6C'}
];

@Pipe({
  name: 'secondReportCollectionState'
})
export class SecondReportCollectionStatePipe implements PipeTransform {
  transform(status: any, type: string) {
    let tempObj: any = secondReportCollectionStateArrs.find((item: any) => {
      return item.value == status;
    })

    if (type === 'color') {
      return tempObj?.color || '';
    } else {
      return tempObj?.label || '-';
    }
  }
}

/**
 * ------------------------------ 报表 ------------------------------
 * 付款平台 1支付宝 2微信 3银联
 */
export const secondReportPayModeArrs = [
  {value: 1, label: '支付宝', color: '#409EFF'},
  {value: 2, label: '微信', color: '#67C23A'},
  {value: 3, label: '银联', color: '#909399'}
];

@Pipe({
  name: 'secondReportPayMode'
})
export class SecondReportPayModePipe implements PipeTransform {
  transform(status: any, type: string) {
    let tempObj: any = secondReportPayModeArrs.find((item: any) => {
      return item.value == status;
    })

    if (type === 'color') {
      return tempObj?.color || '';
    } else {
      return tempObj?.label || '-';
    }
  }
}

/**
 * ------------------------------ 报表 ------------------------------
 * 二手出库状态 1草稿 2待审核 3待打包 4待出库 5已出库 6已签收 7已取消 8审核不通过 9物流异常
 */
export const secondOutStatusArrs = [
  {value: 1, label: '草稿', color: '##909399'},
  {value: 2, label: '待审核', color: '#E6A23C'},
  {value: 3, label: '待打包', color: '#E6A23C'},
  {value: 4, label: '待出库', color: '#e67e22'},
  {value: 5, label: '已出库', color: '#67C23A'},
  {value: 6, label: '已签收', color: '#2ecc71'},
  {value: 7, label: '已取消', color: '#bdc3c7'},
  {value: 8, label: '审核不通过', color: '#bdc3c7'},
  {value: 9, label: '物流异常', color: '#e74c3c'}
];

@Pipe({
  name: 'secondOutStatus'
})
export class SecondOutStatusPipe implements PipeTransform {
  transform(status: any, type: string) {
    let tempObj: any = secondOutStatusArrs.find((item: any) => {
      return item.value == status;
    })

    if (type === 'color') {
      return tempObj?.color || '';
    } else {
      return tempObj?.label || '-';
    }
  }
}
